package beavers.studio.golfberry.screens;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.TextField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class RegisterScreen extends GolfScreen {

	public RegisterScreen() {
		//Super
		super(GolfScreen.ID.REGISTER);
				
		//Add label
		add(new LabelField("Registration"));
		
		//Add manager
		HorizontalFieldManager TableManager = new HorizontalFieldManager();
		VerticalFieldManager LabelManager	= new VerticalFieldManager();
		VerticalFieldManager EditManager	= new VerticalFieldManager();
		TableManager.add(LabelManager);
		TableManager.add(EditManager);
		add(TableManager);
		
		//Create textfields
		String[] Labels = new String[] { "Name", "Company", "Handycap", "Shirt size", "E-Mail"	};
		m_Fields = new TextField[Labels.length];
		
		//For each field
		for (int i = 0; i < m_Fields.length; i++) {
			//Create textfield
			m_Fields[i] = new TextField();
			
			//Add label and field
			LabelManager.add(new LabelField(Labels[i]));
			EditManager.add(m_Fields[i]);
		}
		
		//Create button
		final ButtonField Button = new ButtonField("Register", FIELD_RIGHT);
		add(Button);
		
		//Set listener
		Button.setChangeListener(
			new FieldChangeListener() {
				public void fieldChanged(Field field, int context) {
					//Save data
					
					//Show dialog
					UiApplication.getUiApplication().pushModalScreen(new RegisterDialog(null));
				}
			}
		);
	}
	
	protected boolean navigationMovement(int dx, int dy, int status, int time) {
		//If right
    	/*if (dx > 0) {
    		//Next tab
    		m_GolfTab.next();
    		m_GolfTab.getManager().invalidate();
    	} else if (dx < 0) {
    		//Previous tab
    		m_GolfTab.previous();
    		m_GolfTab.getManager().invalidate();
    	}*/
    	
    	//Disable default navigation
    	return false;
    }
	
	protected TextField[] m_Fields;
}
